#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    ui->tableWidget->insertRow(0);
    ui->tableWidget->insertRow(1);
    ui->tableWidget->insertRow(2);
    ui->tableWidget->insertColumn(0);
    ui->tableWidget->insertColumn(1);
    ui->tableWidget->insertColumn(2);
    ui->tableWidget->setItem(0, 0, new QTableWidgetItem("双层蔬脆牛堡"));
    ui->tableWidget->setItem(0, 1, new QTableWidgetItem("麦乐鸡块"));
    ui->tableWidget->setItem(0, 2, new QTableWidgetItem("可乐"));
    ui->tableWidget->setItem(1, 0, new QTableWidgetItem("巨无霸"));
    ui->tableWidget->setItem(1, 1, new QTableWidgetItem("中薯条"));
    ui->tableWidget->setItem(1, 2, new QTableWidgetItem("雪碧"));
    ui->tableWidget->setItem(2, 0, new QTableWidgetItem("香辣鸡腿堡"));
    ui->tableWidget->setItem(2, 1, new QTableWidgetItem("麦辣鸡翅"));
    ui->tableWidget->setItem(2, 2, new QTableWidgetItem("橙汁"));
    ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("汉堡"));
    ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("小食"));
    ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("饮料"));
    ui->tableWidget->setVerticalHeaderItem(0, new QTableWidgetItem("套餐1"));
    ui->tableWidget->setVerticalHeaderItem(1, new QTableWidgetItem("套餐2"));
    ui->tableWidget->setVerticalHeaderItem(2, new QTableWidgetItem("套餐3"));
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_insertrow_clicked()
{
    ui->tableWidget->insertRow(ui->tableWidget->rowCount());
    ui->tableWidget->setVerticalHeaderItem(ui->tableWidget->rowCount() - 1,new QTableWidgetItem(ui->lineEdit->text()));
    ui->lineEdit->setText("");
}

void Widget::on_pushButton_deleterow_clicked()
{
    ui->tableWidget->removeRow(ui->tableWidget->currentRow());
}

void Widget::on_pushButton_insertcol_clicked()
{
    ui->tableWidget->insertColumn(ui->tableWidget->columnCount());
    ui->tableWidget->setHorizontalHeaderItem(ui->tableWidget->columnCount() - 1,new QTableWidgetItem(ui->lineEdit->text()));
    ui->lineEdit->setText("");
}

void Widget::on_pushButton_deletecol_clicked()
{
    ui->tableWidget->removeColumn(ui->tableWidget->currentColumn());
}
